<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录(html)</title>
</head>
<body>

<div>
    <input id="username"/>
    <button id="btnLogin" type="button">登录</button>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script>
    $(document).ready(function () {
        $('#btnLogin').bind('click', btnLoginClcik)
    })


    function btnLoginClcik() {
        // sessionStorage.setItem("username",$('#username').val());
        $.ajax({
            url: '',
            method: 'post',
            dataType: 'json',
            params: {
                username: $('#username').val()
            }, success: function (data) {
                 /*如果用户名和密码正确，跳转登录页面，显示用户名*/
                /*否则，留在登录页面，并打印错误信息*/

                if(data.flag)
                {
                    window.sessionStorage.setItem("username",data.user.username);
                    window.location.href="index.html";
                }else{
                     //显示报错信息
                }
            }
        })


    }
</script>

</html>